/**
 * Jun 24, 2014 3:06:04 PM
 */
package elitech.vietnam.myfashion.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import elitech.vietnam.myfashion.MainActivity;
import elitech.vietnam.myfashion.R;

/**
 * @author Cong
 *
 */
public class NotificationSettingFragment extends Fragment implements OnCheckedChangeListener, OnClickListener {

	MainActivity mActivity;

	CheckBox mCbEnable, mCbFriendPost, mCbMyStyle, mCbReply, mCbFriendAddMe, mCbSound;
	View mMainTitle, mMenuTop, mFloatMenu;
	
	public NotificationSettingFragment() {
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mActivity = (MainActivity) getActivity();
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.settings_notifications, container, false);
		
		mCbEnable = (CheckBox) view.findViewById(R.id.stnoti_cbEnable);
		mCbFriendPost = (CheckBox) view.findViewById(R.id.stnoti_cbFriendPost);
		mCbMyStyle = (CheckBox) view.findViewById(R.id.stnoti_cbMystyleComment);
		mCbReply = (CheckBox) view.findViewById(R.id.stnoti_cbReplyComment);
		mCbFriendAddMe = (CheckBox) view.findViewById(R.id.stnoti_cbFriendAddMe);
		mCbSound = (CheckBox) view.findViewById(R.id.stnoti_cbEnableSound);
		mMainTitle = view.findViewById(R.id.main_title);
		mMenuTop = view.findViewById(R.id.ImageView01);
		mFloatMenu = view.findViewById(R.id.btnFloatMenu);
		
		boolean mNotiEnable = mActivity.mPrefs.getBoolean("GetNotification", true);
		boolean mNotiFriendPost = mActivity.mPrefs.getBoolean("GetNotiPost", true);
		boolean mNotiComment = mActivity.mPrefs.getBoolean("GetNotiComent", true);
		boolean mNotiRepComment = mActivity.mPrefs.getBoolean("GetNotiReply", true);
		boolean mNotiAddFriend = mActivity.mPrefs.getBoolean("GetNotiFollow", true);
		boolean mNotiSound = mActivity.mPrefs.getBoolean("GetNotiSound", true);
		
		mCbEnable.setChecked(mNotiEnable);
		mCbFriendPost.setChecked(mNotiFriendPost);
		mCbMyStyle.setChecked(mNotiComment);
		mCbReply.setChecked(mNotiRepComment);
		mCbFriendAddMe.setChecked(mNotiAddFriend);
		mCbSound.setChecked(mNotiSound);
		
		mCbFriendPost.setEnabled(mNotiEnable);
		mCbMyStyle.setEnabled(mNotiEnable);
		mCbReply.setEnabled(mNotiEnable);
		mCbFriendAddMe.setEnabled(mNotiEnable);
		
		mCbEnable.setOnCheckedChangeListener(this);
		mCbFriendPost.setOnCheckedChangeListener(this);
		mCbMyStyle.setOnCheckedChangeListener(this);
		mCbReply.setOnCheckedChangeListener(this);
		mCbFriendAddMe.setOnCheckedChangeListener(this);
		mCbSound.setOnCheckedChangeListener(this);

		mMainTitle.setOnClickListener(this);
		mMenuTop.setOnClickListener(this);
		mFloatMenu.setOnClickListener(this);
		
		return view;
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		String mKey = "";
		switch (buttonView.getId()) { 
		case R.id.stnoti_cbEnable: 
			mKey = "GetNotification";
			mCbFriendPost.setEnabled(isChecked);
			mCbMyStyle.setEnabled(isChecked);
			mCbReply.setEnabled(isChecked);
			mCbFriendAddMe.setEnabled(isChecked);
//			if (isChecked) {
//				mCbFriendPost.setChecked(isChecked); mActivity.mOptions.mNotiFriendPost = isChecked;
//				mCbMyStyle.setChecked(isChecked); mActivity.mOptions.mNotiComment = isChecked;
//				mCbReply.setChecked(isChecked); mActivity.mOptions.mNotiRepComment= isChecked;
//				mCbFriendAddMe.setChecked(isChecked); mActivity.mOptions.mNotiAddFriend = isChecked;
//			}
			break;
		case R.id.stnoti_cbEnableSound:
			mKey = "GetNotiSound";	
			break;
		case R.id.stnoti_cbFriendPost:
			mKey = "GetNotiPost";
			break;
		case R.id.stnoti_cbMystyleComment:
			mKey = "GetNotiComent";
			break;
		case R.id.stnoti_cbReplyComment:
			mKey = "GetNotiReply";
			break;
		case R.id.stnoti_cbFriendAddMe:
			mKey = "GetNotiFollow";
			break;
		default:
			break;
		}
		mActivity.mPrefs.edit().putBoolean(mKey, isChecked).commit();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.main_title:
		case R.id.ImageView01:
		case R.id.btnFloatMenu:
			mActivity.callMenu();
			break;
		default:
			break;
		}
	}
}
